// Finds the even elements of an array
import java.util.Scanner;
public class Example4 {
	  public static void main(String[] args) {
    	Scanner scanner = new Scanner(System.in);
        int[] values, evenValues;
        values = readArray();
        evenValues = getEvenValues(values);
        if(evenValues.length == 0)
            System.out.printf("There are no even values in the array.");
        else if (evenValues.length == 1)
             System.out.printf("The even value in the array is: %d", evenValues[0]);
        else{
            System.out.printf("%nThe even values in the array are:%n");
            printArray(evenValues);
        }
    }

    private static int[] readArray(){
    	Scanner scanner = new Scanner(System.in);
    	System.out.printf("Enter number of elements: ");
    	int size = scanner.nextInt();
    	int[] x = new int[size];
    	for(int index = 0; index < size; index++){
    		System.out.printf("Enter element x[%d]: ", index);
    		x[index] = scanner.nextInt();
    	}
    	return x;
    }

    private static void printArray(int[] array){
    	for(int k = 0; k < array.length; k++)
    		System.out.printf("%d  ", array[k]);
    }

    private static int[] getEvenValues(int[] x){
    	int y[] = new int[x.length];
    	int count = 0;
    	for(int k = 0; k < x.length; k++){
    		if(x[k] % 2 == 0){
    			y[count] = x[k];
    			count++;
    		}
    	}

    	if(count == x.length)
    		return y;
    	else{
    		int[] z = new int[count];
    		for(int k = 0; k < count; k++){
    			z[k] = y[k];
    		}

    		return z;
    	}
    }
}
